package iosr11.example;

import iosr11.Service.EventSeriesService;
import iosr11.Service.EventService;
import iosr11.Service.ServiceCreator;
import iosr11.Service.ServiceLocatorImpl;
import iosr11.Service.StudentService;
import iosr11.Service.TeacherService;
import iosr11.data.Attendence;
import iosr11.data.Event;
import iosr11.data.EventSeries;
import iosr11.data.Student;
import iosr11.data.Teacher;

public class EventSeriesMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ServiceCreator.createService();
		EventSeriesService serviceES = (EventSeriesService) ServiceLocatorImpl.getInstance().getService(EventSeries.class);
		TeacherService teacherS = (TeacherService) ServiceLocatorImpl.getInstance().getService(Teacher.class);
		StudentService studS = (StudentService) ServiceLocatorImpl.getInstance().getService(Student.class);
		EventService eventS = (EventService) ServiceLocatorImpl.getInstance().getService(Event.class);

		//Teacher te = teacherS.getAllTeachers().get(0);
		//System.out.println(te);
		//Event ev = eventS.getEvent();
	/*	
		String id ="http://www.google.com/base/feeds/items/6862078464135439599";
		Event ev = eventS.getCurrentEvent();
		System.out.println(ev);
		System.out.println("-----");
		System.out.println(ev.getSeries().getTeacher());
		
		
*/		
		Event ev = eventS.getCurrentEvent();
		System.out.println(ev.getAttendences().get(0).getStudent().getProjectGrp().getGroupName());
		/*
		for (Attendence at : ev.getAttendences()){
			System.out.println("ob: = "+at.getPressence());
			System.out.println("st: = "+at.getStudent());
		}
		
		/*
		String id ="http://www.google.com/base/feeds/items/6862078464135439599";
		Event ev = eventS.getEvent(id);
		Date dataS = new Date();
		Date dataE = new Date();
		System.out.println(ev.getStartDate());
		dataS.setDate(12);
		dataS.setMonth(8);
		dataS.setYear(2009);
		dataS.setHours(12);
		dataS.setMinutes(30);
		dataS.setSeconds(0);
		dataE.setDate(13);
		dataE.setMonth(8);
		dataE.setYear(2009);
		dataE.setHours(12);
		dataE.setMinutes(30);
		dataE.setSeconds(0);
		ev.setStartDate(dataS);
		ev.setEndDate(dataE);
		System.out.println(ev.getStartDate());
		System.out.println(eventS.updateEvent(ev));*/
		//System.out.println(ev.getId());
		//System.out.println(ev.getAttendences().get(0).getStudent());
		
		//System.out.println(serviceES.createEventSeries(EventKind.LABOLATORY, te, null));
		//http://www.google.com/base/feeds/items/10131563313483216060
		//http://www.google.com/base/feeds/items/3065930553745508877
		
		/*
		List<EventSeries> ser = serviceES.getAllEventSeries();
		for(EventSeries tm : ser){
			System.out.println(tm.getId());
		}
		EventSeries series = serviceES.getAllEventSeries().get(0);
		
		System.out.println("====================EVENTY =================");
		List <Student> tst = studS.getStudentsForEventSeries(series);
		System.out.println(tst);
		
		//System.out.println(series.getTeacher());
		//*/
		/*
		System.out.println(eventS.getCurrentEvent());
		
		//System.out.println(serviceES.getAllEventSeries());
		
		List<Student> student = studS.getAllStudents();
		System.out.println(student);
		Student s = student.get(0);
		
		//List<EventSeries> ser = serviceES.getStudentEventSeries(s);
		
		Event ev = eventS.getStudentEvents(s).get(0);
		System.out.println(studS.getStudentsForEvent(ev));
		//System.out.println(studS.getStudentByID("http://www.google.com/base/feeds/items/6323546425088276483"));
		//System.out.println(studS.getStudentsForEventSeries(ser.get(0)));
		/*
		//System.out.println(serviceES.addStudentToEvents(student, series));
		Date end = new Date();
		Date start = new Date();
		end.setYear(2008);
		end.setMonth(10);
		end.setDate(30);
		end.setHours(14);
		end.setMinutes(0);
		
		start.setYear(2008);
		start.setMonth(10);
		start.setDate(30);
		start.setHours(12);
		start.setMinutes(0);
		
		Event event = new Event();
		event.setAttendences(null);
		event.setDeadline(true);
		event.setDescription("lab 03 - zakończenie");
		event.setStartDate(start);
		event.setEndDate(end);
		event.setNotes(null);
		event.setPlace("sala 210");
		event.setSeries(series);
		
		System.out.println(eventS.addEvent(event));
		// */
		
		/*
		//for (int i=0;i<student.size();i++){
			//if (!student.get(i).getEmail().equals("tadeusz.k@gmail.com"))
			//	System.out.println("------------------------> dodaje");
			//	System.out.println(serviceES.addStudentToEvents(student.get(i), series));
			System.out.println("====================STUDENT======================");
			List<Event> events = eventS.getAllEvents();
			System.out.println(events);
			System.out.println(events.size());
		//}
		// */
		
		
//		String id = eventS.getAllEvents().get(0).getId();
		//System.out.println(eventS.getEvent(id));
		
/*		
		
		EventSeries es = new EventSeries();
		Teacher teacher = teacherS.getTeacher("teacher1@gmail.com");
		es.setEvents(null);
		es.setKind(EventKind.EXAM);
		es.setTeacher(teacher);
		
		
		//System.out.println(serviceES.addEventSeries(es));
		
		Student stud = studS.getStudent("anton.k@gmail.com");
		System.out.println(stud);
		//EventSeries series = serviceES.getAllEventSeries().get(1);
		//System.out.println(series.getKind());
		Calendar cal = Calendar.getInstance();
		DateTime time = new DateTime(cal.getTimeInMillis());
		System.out.println("time = "+time.toString());
		System.out.println("time2 = "+cal.getTime().toString());
		
		Calendar startDate = Calendar.getInstance();
		startDate.set(Calendar.DAY_OF_MONTH, 27);
		startDate.set(Calendar.MONTH, 3);
		startDate.set(Calendar.HOUR, 12);
		startDate.set(Calendar.MINUTE, 30);
		System.out.println("sart = "+startDate.getTime().toString());
		
		Calendar endDate = Calendar.getInstance();
		endDate.set(Calendar.DAY_OF_MONTH, 27);
		endDate.set(Calendar.MONTH, 3);
		endDate.set(Calendar.HOUR, 14);
		endDate.set(Calendar.MINUTE, 0);
		System.out.println("end = "+endDate.getTime().toString());
		
		Event event = new Event();
		
		event.setAttendences(null);
		event.setDeadline(false);
		event.setDescription("zajecia");
		event.setStartDate(startDate);
		event.setEndDate(endDate);
		event.setNotes(null);
		event.setPlace("jakas sala");
		
		//System.out.println(serviceES.addStudentToEvents(stud, series));
		List<EventSeries> lista = serviceES.getStudentEventSeries(stud);
		
		event.setSeries(lista.get(0));
		
		//System.out.println(eventS.addEvent(event));
		
		System.out.println("Lista event serii");
		for (EventSeries ser : lista){
			System.out.println(ser.getKind());
		}
		
		List<Event> lista2 = eventS.getStudentEvents(stud);
		System.out.println("Lista eventow");
		
		for (Event ev : lista2){
			//System.out.println(ev.getDescription()+"  "+ev.getSeries().getKind() + "  " + ev.getId());
			System.out.println(ev.toString());
		}
		
//*/		
		//System.out.println(serviceES.getAllEventSeries().get(0));
		/*
		Event event = new Event();
		
		event.setSeries(null);
		event.setAttendences(null);
		event.setDeadline(false);
		event.setDescription("zajecia");
		event.setStartDate(new Date());
		event.setEndDate(new Date());
		event.setNotes(null);
		event.setPlace("jakas sala");
		System.out.println(eventS.createEvent(new Date(), new Date(), "testowe", null, false, "sdfghjktyui"));
		*/
	}

}
